using System;
using System.Drawing;
using System.ComponentModel;

namespace Camalon.Drawing
{
    /// <summary>
    /// Specifies the style of the corner to be drawn
    /// </summary>
	public enum CornerStyle
	{
        /// <summary>
        /// Specifies an elliptic corner
        /// </summary>
		Elliptic,
        /// <summary>
        /// Specifies a line based corner
        /// </summary>
		Line
	}

    /// <summary>
    /// Corner structure specifies the style, width and height of a corner in a rectangle.
    /// </summary>
	[Serializable]
	[TypeConverter(typeof(CornerConverter))]
	public struct Corner
	{
		private float		_width;
		private float		_height;
		private CornerStyle	_style;
        /// <summary>
        /// Initializes a new instance of the <see cref="Corner"/> struct.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
		public Corner( float width, float height ):this( width, height, CornerStyle.Elliptic ){}

        /// <summary>
        /// Initializes a new instance of the <see cref="Corner"/> struct.
        /// </summary>
        /// <param name="width">The width of corner.</param>
        /// <param name="height">The height of corner.</param>
        /// <param name="style">The corner style.</param>
		public Corner( float width, float height, CornerStyle style )
		{
			_width				= width;
			_height				= height;
			_style				= style;
		}

        /// <summary>
        /// Initializes a new instance of the <see cref="Corner"/> struct.
        /// </summary>
        /// <param name="size">The size.</param>
		public Corner( SizeF size ):this( size, CornerStyle.Elliptic){}


        /// <summary>
        /// Initializes a new instance of the <see cref="Corner"/> struct.
        /// </summary>
        /// <param name="size">The size.</param>
        /// <param name="style">The style.</param>
		public Corner( SizeF size, CornerStyle style )
		{
			_width		= size.Width;
			_height		= size.Height;
			_style		= style;
		}

		#region operatoren
		public override bool Equals(object obj)
		{
			if(!( obj is Corner)) return false;

			return Equals((Corner)obj);
		}

		public bool Equals(Corner value)
		{
			return _width == value._width && _height == value._height && _style == value._style;
		}

		public override int GetHashCode()
		{
			return _width.GetHashCode()^_height.GetHashCode()^_style.GetHashCode();
		}

		public static bool operator ==(	Corner value1,Corner value2	)
		{
			return value1._width == value2._width && value1._height == value2._height && value1._style == value2._style;
		}

		public static bool operator !=(	Corner value1,Corner value2	)
		{
			return !(value1== value2);
		}
		#endregion operatoren


        /// <summary>
        /// Gets the empty corner structure.
        /// </summary>
        /// <value>The empty.</value>
		public static Corner Empty
		{
			get{ return new Corner(0.0f,0.0f);}
		}

        /// <summary>
        /// Gets a value indicating whether this instance is empty.
        /// </summary>
        /// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
		[Browsable(false)]
		public bool IsEmpty
		{
			get{ return _width == 0.0f && _height == 0.0f;}
		}

        /// <summary>
        /// Gets the identity corner.
        /// </summary>
        /// <value>The identity.</value>
		public static Corner Identity
		{
			get{ return new Corner(1.0f,1.0f);}
		}

        /// <summary>
        /// Gets a value indicating whether this instance is identity.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is identity; otherwise, <c>false</c>.
        /// </value>
		[Browsable(false)]
		public bool IsIdentity
		{
			get{ return _width == 1.0f && _height == 1.0f;}
		}



        /// <summary>
        /// Gets or sets the width of the corner.
        /// </summary>
		[DefaultValue( 0.0f )]
		[TypeConverter(typeof(PercentConverter))]
		[RefreshProperties( RefreshProperties.All)]
		public float Width
		{
			get{ return _width;  }
			set
			{ 
				_width = value;
			}
		}


        /// <summary>
        /// Gets or sets the height of the corner.
        /// </summary>
		[DefaultValue( 0.0f )]
		[TypeConverter(typeof(PercentConverter))]
		[RefreshProperties( RefreshProperties.All)]
		public float Height
		{
			get{ return _height;  }
			set
			{ 
				_height = value;
			}
		}

        /// <summary>
        /// Gets or sets the corner style.
        /// </summary>
		[DefaultValue( CornerStyle.Elliptic )]
		[RefreshProperties( RefreshProperties.All)]
		public CornerStyle Style
		{
			get{ return _style;  }
			set
			{ 
				_style = value;
			}
		}

        /// <summary>
        /// Gets the size of the corner.
        /// </summary>
		[Browsable( false)]
		public SizeF Size
		{
			get{ return new SizeF(_width,_height);}
		}

        /// <summary>
        /// Gets the point. The X value of point represents width and Y value represents the Height of the corner
        /// </summary>
		[Browsable( false)]
		public PointF Point
		{
			get{ return new PointF(_width,_height);}
		}

	}




}
